package com.onedec.menu.service.impl;

import com.onedec.menu.dao.OnedecRolePermissionDao;

import com.onedec.menu.entity.OnedecRolePermission;
import com.onedec.menu.entity.OnedecRolePermissionExample;
import com.onedec.menu.service.RolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service

public class RolePermissionServiceImpl implements RolePermissionService {
@Autowired
private OnedecRolePermissionDao onedecRolePermissionDao;

    @Override
    public List<OnedecRolePermission> selectPermissionByRoleid(int id) {
        OnedecRolePermissionExample example = new OnedecRolePermissionExample();
        OnedecRolePermissionExample.Criteria or = example.or();
        or.andRoleIdEqualTo(id);
        return onedecRolePermissionDao.selectByExample(example);
    }

    @Override
    public void insert(OnedecRolePermission onedecRolePermission) {
        onedecRolePermissionDao.insertSelective(onedecRolePermission);
    }

    @Override
    public List<OnedecRolePermission> selectByRoleIdAndPermissionId(int roleId, int permissionId) {
        OnedecRolePermissionExample example = new OnedecRolePermissionExample();
        OnedecRolePermissionExample.Criteria or = example.or();
        or.andRoleIdEqualTo(roleId);
        or.andPermissionIdEqualTo(permissionId);
        return onedecRolePermissionDao.selectByExample(example);
    }

    @Override
    public void delete(int roleId) {
        OnedecRolePermissionExample example = new OnedecRolePermissionExample();
        OnedecRolePermissionExample.Criteria or = example.or();
        or.andRoleIdEqualTo(roleId);
        onedecRolePermissionDao.deleteByExample(example);
    }
}
